﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Javascript.aspx.cs" Inherits="Orbitone.MeetingRooms.RoomFinder.Javascript" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

   <link rel="stylesheet" type="text/css" href="style.css" />
<script src="https://js.live.net/v5.0/wl.js" type="text/javascript"></script>
    <script type="text/javascript">
        var APPLICATION_CLIENT_ID = "000000004805B83C",
        REDIRECT_URL = "http://rooms2.oneoffice.be:51233/javascript.aspx";
        WL.Event.subscribe("auth.login", onLogin);
        WL.init({
            client_id: APPLICATION_CLIENT_ID,
            redirect_uri: REDIRECT_URL,
            response_type: "token"
        });
        WL.ui({
            name: "signin",
            element: "signInButton"
        });

        function greetUser(session) {
            var strGreeting = "";
            WL.api(
            {
                path: "me",
                method: "GET"
            },
            function (response) {
                if (!response.error) {
                    strGreeting = "Hi, " + response.first_name + "!"
                    document.getElementById("greeting").innerHTML = strGreeting;
                }
            });
        }
        function setMeImage(token) {
            var imgHolder = document.getElementById("meimg"),
            imgTagString = "";

            if (token != null) {
                var url = "https://apis.live.net/v5.0/me/picture?oauth_token=" + escape(token);
                imgTagString = "<img src='" + url + "' />";
            }
            imgHolder.innerHTML = imgTagString;
        }
        function onLogin() {
            var session = WL.getSession();
            if (session) {
                greetUser(session);
                setMeImage(session.access_token);
            }
        }
    </script>

    <p>Sign in to display a welcome greeting.</p>
    <div id="meimg"></div>
    <div id="greeting"></div>
    <div id="signInButton"></div>

</asp:Content>
